package com.person.jiaiplan.controller;

import com.person.jiaiplan.pojo.R;
import com.person.jiaiplan.pojo.dto.expenses.ExpensesAddPlanReqDTO;
import com.person.jiaiplan.pojo.dto.expenses.ExpensesFinishReqDTO;
import com.person.jiaiplan.pojo.dto.expenses.ExpensesPlanQueryReqDTO;
import com.person.jiaiplan.pojo.dto.expenses.ExpensesPlanQueryResDTO;
import com.person.jiaiplan.service.ExpensesPlanService;
import com.person.jiaiplan.service.ExpensesService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 计划花销管理
 */
@AllArgsConstructor
@RestController
@RequestMapping("expenses/plan/")
@Validated
@Slf4j
public class ExpensesPlanController {

    /**
     * 计划花销
     */
    @Autowired
    private ExpensesPlanService expensesPlanService;

    /**
     * 计划花销
     */
    @Autowired
    private ExpensesService expensesService;

    @PostMapping("query")
    public R<List<ExpensesPlanQueryResDTO>> query(@RequestBody ExpensesPlanQueryReqDTO reqDTO) {
        return R.ok(expensesPlanService.queryExpensesPlan(reqDTO));
    }

    /**
     * 新建计划花销
     *
     * @param
     * @return
     */
    @PostMapping("add")
    public R<Boolean> add(@RequestBody @Validated ExpensesAddPlanReqDTO reqDTO) {
        return R.ok(expensesPlanService.addPlan(reqDTO));
    }

    @PostMapping("edit")
    public R<Boolean> edit(@RequestBody @Validated ExpensesAddPlanReqDTO reqDTO) {
        return R.ok(expensesPlanService.editPlan(reqDTO));
    }

    @PostMapping("finish")
    public R<Boolean> finishIt(@RequestBody @Validated ExpensesFinishReqDTO reqDTO) {
        return R.ok(expensesService.finishIt(reqDTO));
    }

    @DeleteMapping("delete")
    public R<Boolean> deleteIt(@RequestParam(name = "id") String Id){
        return R.ok(expensesService.deletePlan(Id));
    }

}
